﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DelonixRegiaHotel.Classes;

namespace DelonixRegiaHotel
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

        }

        Form mdiChildForm = new Form();
        public void Form1_Load(object sender, System.EventArgs e)
        {
            MdiClient ctlMDI;

            foreach (Control ctl in this.Controls)
            {
                try
                {
                    // Attempt to cast the control to type MdiClient.
                    ctlMDI = (MdiClient)ctl;

                    // Set the BackColor of the MdiClient control.
                    ctlMDI.BackColor = this.BackColor;
                }
                catch (InvalidCastException exc)
                {
                    // Catch and ignore the error if casting failed.
                }
            }

            // Set the IsMdiContainer property to true.
            IsMdiContainer = true;

            // Set the child form's MdiParent property to  
            // the current form.
            mdiChildForm.MdiParent = this;
            SetBackGroundColorOfMDIForm();

        }



        public void callForm(Form newForm)
        {
            if (CheckOpened(newForm.Text) == false)
            {
                newForm.MdiParent = this;
                // Display the new form.
                newForm.StartPosition = FormStartPosition.CenterScreen;
                newForm.Show();
            }
            newForm.Focus();
        }


        public bool CheckOpened(string name)
        {
            FormCollection fc = Application.OpenForms;
            foreach (Form frm in fc)
            {
                if (frm.Text == name)
                {
                    return true;
                }
            }
            return false;
        }

        private void SetBackGroundColorOfMDIForm()
        {
            foreach (Control ctl in this.Controls)
            {
                if ((ctl) is MdiClient)

                // If the control is the correct type,
                // change the color.
                {
                    ctl.BackColor = System.Drawing.Color.Purple;
                }
            }

        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CheckIn newMDIChild = new CheckIn();
            // Set the Parent Form of the Child window.
            callForm(newMDIChild);
            
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void bookingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ManageBooking newMDIChild = new ManageBooking();
            // Set the Parent Form of the Child window.
            callForm(newMDIChild);
        }

        private void newCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateCustomer newMDIChild = new CreateCustomer();
            callForm(newMDIChild);
        }

        private void newDutyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateDuty newMDIChild = new CreateDuty();
            callForm(newMDIChild);
        }

        private void viewDutiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetDuty newMDIChild = new GetDuty();
            callForm(newMDIChild);
        }

        private void updateDutiesToolStripMenuItem1_Click(object sender, EventArgs e)
        {

            GetDuty newMDIChild = new GetDuty();
            callForm(newMDIChild);

        }

        private void updateCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdateCustomer newMDIChild = new UpdateCustomer();
            callForm(newMDIChild);
        }

        private void deleteCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DeleteCustomer newMDIChild = new DeleteCustomer();
            callForm(newMDIChild);
        }

        private void newCardInfoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateCreditCard newMDIChild = new CreateCreditCard();
            callForm(newMDIChild);
        }

        private void updateCardInfoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdateCreditCard newMDIChild = new UpdateCreditCard();
            callForm(newMDIChild);
        }

        private void deleteCardInfoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DeleteCreditCard newMDIChild = new DeleteCreditCard();
            callForm(newMDIChild);
        }

        private void createStaffToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateStaff newMDIChild = new CreateStaff();
            callForm(newMDIChild);
        }

        private void updateDutiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetStaff newMDIChild = new GetStaff();
            callForm(newMDIChild);
        }

        private void deleteStaffToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DeleteStaff newMDIChild = new DeleteStaff();
            callForm(newMDIChild);
        }


        private void updateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdditionalCheckInItems newMDIChild = new AdditionalCheckInItems();
            callForm(newMDIChild);
        }

        private void checkOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CheckOut newMDIChild = new CheckOut();
            callForm(newMDIChild);
        }


        private void staffAccountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StaffEditInfo newMDIChild = new StaffEditInfo();
            callForm(newMDIChild);
        }



        private void advanceBookingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdvanceBookingForm newMDIChild = new AdvanceBookingForm();
            callForm(newMDIChild);
        }

        private void statusReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RoomStatus newMDIChild = new RoomStatus();
            callForm(newMDIChild);
        }

        private void roomGuestListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RoomGuestList newMDIChild = new RoomGuestList();
            callForm(newMDIChild);
        }

        private void arrivalListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ArrivalList newMDIChild = new ArrivalList();
            callForm(newMDIChild);
        }

        private void roomOccupancyReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RoomOccupancyDaily newMDIChild = new RoomOccupancyDaily();
            callForm(newMDIChild);
        }

        private void staffDutyListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HousekeepingDutyList newMDIChild = new HousekeepingDutyList();
            callForm(newMDIChild);
        }

        private void dailyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HousekeepingDailySchedule newMDIChild = new HousekeepingDailySchedule();
            callForm(newMDIChild);
        }

        private void weeklyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HousekeepingWeeklySchedule newMDIChild = new HousekeepingWeeklySchedule();
            callForm(newMDIChild);
        }
    }
}
